package com.qiaodata.datatrans.utils;

import io.swagger.models.auth.In;

import java.util.*;

/**
 * Created by Administrator on 2016/12/22 0022.
 */
public class MapAndListUtil {
    public static void main(String[] args) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        map.put(1, 8);
        map.put(3, 12);
        map.put(5, 53);
        map.put(123, 33);
        map.put(42, 11);
        map.put(44, 42);
        map.put(15, 3);

        System.out.println(getMaxKey(map));
        System.out.println(getMaxValue(map));

        List<Integer> list = new ArrayList<>();
        list.add(2);
        list.add(6);
        list.add(4);
        list.add(7);
        list.add(9);
        int i = list.indexOf(4);
        System.out.println(i);
    }

    /**
     * 求Map<K,V>中Key(键)的最大值
     * @param map
     * @return
     */
    public static Object getMaxKey(Map<Integer, Integer> map) {
        if (map == null) return null;
        Set<Integer> set = map.keySet();
        Object[] obj = set.toArray();
        Arrays.sort(obj);
        return obj[obj.length-1];
    }

    /**
     * 求Map<K,V>中Value(值)的最大值
     * @param map
     * @return
     */
    public static Object getMaxValue(Map<Integer, Integer> map) {
        if (map == null) return null;
        Collection<Integer> c = map.values();
        Object[] obj = c.toArray();
        Arrays.sort(obj);
        Integer maxValue = (Integer) obj[obj.length - 1];
        return obj[obj.length-1];
    }

    //集合值最大的值对应的索引
    public static int listArrayMaxValueIndex(List<Long> dataList) {
        Long max = 0l;
        for (Long ds : dataList) {
            if (ds > max) {
                max = ds;
            }
        }
        int i = dataList.indexOf(max);
        return i;
    }

    //集合值最大的值
    public static Long listArrayMaxValue(List<Long> dataList) {
        Long max = 0l;
        for (Long ds : dataList) {
            if (ds > max) {
                max = ds;
            }
        }
        return max;
    }

    //集合值最小的值
    public static Long listArrayMinValue(List<Long> dataList) {
        Long min = 0l;
        for (Long ds : dataList) {
            if (ds < min) {
                min = ds;
            }
        }
        return min;
    }

}
